package com.snowfeel.sfmall.sys.controller;

import com.snowfeel.sfmall.core.param.IdParam;
import com.snowfeel.sfmall.core.param.IdsParam;
import com.snowfeel.sfmall.core.response.JsonResult;
import com.snowfeel.sfmall.core.vo.PageVo;
import com.snowfeel.sfmall.sys.dto.SysDictItemParam;
import com.snowfeel.sfmall.sys.query.SysDictItemQuery;
import com.snowfeel.sfmall.sys.service.SysDictItemService;
import com.snowfeel.sfmall.sys.vo.SysDictItemVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "字典数据接口")
@RestController
@RequestMapping("/dict/items")
public class SysDictItemController {

    @Autowired
    private SysDictItemService dictItemService;

    @ApiOperation(value = "字典数据分页列表")
    @PostMapping("/page")
    public JsonResult<PageVo<SysDictItemVo>> page(@RequestBody SysDictItemQuery query) {
        PageVo<SysDictItemVo> result = dictItemService.page(query);
        return JsonResult.success(result);
    }

    @ApiOperation(value = "字典数据表单数据")
    @PostMapping("/detail")
    public JsonResult<SysDictItemVo> detail(@ApiParam("字典ID") @RequestBody IdParam param) {
        SysDictItemVo formData = dictItemService.detail(param);
        return JsonResult.success(formData);
    }

    @ApiOperation(value = "新增字典数据")
    @PostMapping("/create")
    public JsonResult create(@RequestBody SysDictItemParam dictItemParam) {
        boolean result = dictItemService.create(dictItemParam);
        return JsonResult.success(result);
    }

    @ApiOperation(value = "修改字典数据")
    @PostMapping("/update/{id}")
    public JsonResult update(@PathVariable Long id,
                                     @RequestBody SysDictItemParam dictItemParam) {
        boolean status = dictItemService.update(id, dictItemParam);
        return JsonResult.success(status);
    }

    @ApiOperation(value = "删除字典")
    @PostMapping("/deleteBatch")
    public JsonResult deleteBatch(
            @ApiParam("字典ID列表") @RequestBody IdsParam param) {
        boolean result = dictItemService.deleteBatch(param);
        return JsonResult.success(result);
    }

}
